package pl.edu.agh.mguesser.ui.game;

import java.awt.GridLayout;
import javax.annotation.PostConstruct;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.springframework.stereotype.Controller;
import pl.edu.agh.mguesser.game.listener.GameStartedListener;
import pl.edu.agh.mguesser.game.listener.SongRevealedListener;
import pl.edu.agh.mguesser.metadata.Metadata;

/**
 * @author keiran
 */
@Controller
public class SongRevealedPanel extends JPanel implements GameStartedListener,
                                                         SongRevealedListener {

    private JLabel artistLabel;
    private JLabel titleLabel;
    private JLabel albumLabel;
    private JLabel pathLabel;
    
    @PostConstruct
    public void postConstruct() {
        setLayout(new GridLayout(2, 2));
        
        artistLabel = new JLabel();
        add(artistLabel);
        titleLabel = new JLabel();
        add(titleLabel);
        albumLabel = new JLabel();
        add(albumLabel);
        pathLabel = new JLabel();
        add(pathLabel);
    }

    @Override
    public void gameStarted() {
        clear();
    }

    @Override
    public void songRevealed(Metadata metadata) {
        artistLabel.setText("ARTIST: " + metadata.getArtist());
        titleLabel.setText("TITLE: " + metadata.getTitle());
        albumLabel.setText("ALBUM: " + metadata.getAlbum());
        pathLabel.setText("PATH: " + metadata.getPath().toString());
        pathLabel.setToolTipText(metadata.getPath().toString());
    }

    @Override
    public void userAnswered() {
        clear();
    }

    private void clear() {
        artistLabel.setText("");
        titleLabel.setText("");
        albumLabel.setText("");
        pathLabel.setText("");
        pathLabel.setToolTipText("");
    }

}
